<template>
	<view class="navbar" :style="{height: navBarHeight + statusBarHeight + 'px'}">
		<view class="navbar_fixed">
			<view :style="{height: statusBarHeight + 'px'}"></view>
			<view class="navbar-content" :style="{height: navBarHeight + 'px', width: windowWidth + 'px'}">
				<view class="navbar-search">
					<view class="navbar-search_icon">
						<uni-icons type="search" size="16" color="#999"></uni-icons>
					</view>
					<view class="navbar-search_text">uni-app、vue</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight: 20,
				navBarHeight: 45,
				windowWidth: 375
			}
		},
		created() {
			// 获取手机系统信息 -- 动态获取设备状态栏高度
			const { statusBarHeight, windowWidth }  = uni.getSystemInfoSync()
			this.statusBarHeight = statusBarHeight
			this.windowWidth = windowWidth
			
			// h5 app mp-alipay
			// #ifndef H5 || APP-PLUS || MP-ALIPAY
			// 获取胶囊的位置 (胶囊底部的高度 - 状态栏高度) + (胶囊顶部的高度 - 状态朗高度)
			const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			console.log(menuButtonInfo)
			this.navBarHeight = (menuButtonInfo.bottom -statusBarHeight) + (menuButtonInfo.top - statusBarHeight) * 2
			this.windowWidth = menuButtonInfo.left
			// #endif
		}
	}
</script>

<style lang='scss'>
	@import '../../common/css/icons.css';
	.navbar {
		position: relative;
		z-index: 99;
		.navbar_fixed {			
			position: fixed;
			top: 0;
			left: 0;
			z-idnex: 99;
			width: 100%;
			background-color: $base-color;
			.navbar-content {
				display: flex;
				justify-content: center;
				align-items: center;
				padding: 0 30rpx;
				box-sizing: border-box;
				.navbar-search {
					display: flex;
					align-items: center;
					width: 100%;
					height: 30px;
					padding: 0 20rpx;
					border-radius: 30px;
					background-color: #FFFFFF;
					.navbar-search_icon {
						margin-right: 10rpx;
					}
					.navbar-search_text {
						font-size: 12px;
						color: #666;
					}
				}
			}
		}
	}
</style>
